package flowise.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author huangya
 * @date 2024/1/29
 */
public class Utils {

    private static final String[] skipClassNames = {"BaseLangChain", "Serializable"};

    public static List<String> getBaseClasses(Object targetClass) {
        List<String> baseClasses = new ArrayList<>();
        String[] skipClassNames = {"BaseLangChain", "Serializable"};

        if (targetClass instanceof Class<?>) {
            Class<?> baseClass = (Class<?>) targetClass;
            while (baseClass != null) {
                Class<?> newBaseClass = baseClass.getSuperclass();
                if (newBaseClass != null && newBaseClass != Object.class && newBaseClass.getSimpleName() != null) {
                    baseClass = newBaseClass;
                    if (!contains(skipClassNames, baseClass.getSimpleName())) {
                        baseClasses.add(baseClass.getSimpleName());
                    }
                } else {
                    break;
                }
            }
        }
        return baseClasses;
    }

    private static boolean contains(String[] arr, String str) {
        for (String s : arr) {
            if (s.equals(str)) {
                return true;
            }
        }
        return false;
    }


}
